package cn.stronglink.assetmanage.business.inventory.view.detail;

import android.app.Dialog;
import android.support.v4.app.Fragment;
import android.view.View;
import android.widget.Spinner;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.stronglink.assetmanage.R;
import cn.stronglink.assetmanage.entity.InventoryDetail;
import cn.stronglink.assetmanage.utils.ToastUtil;
import cn.stronglink.assetmanage.widget.CustomProgressDialog;

/**
 * Created by chencongcong on 2018/6/15.
 */

public class InventoryDetailView {
    private Fragment fragment;
    @BindView(R.id.tv_inventory_asset_name)
    TextView tv_inventory_asset_name;
    @BindView(R.id.tv_inventory_sn_no)
    TextView tv_inventory_sn_no;
    @BindView(R.id.tv_inventory_rfid_no)
    TextView tv_inventory_rfid_no;
    @BindView(R.id.tv_inventory_asset_class)
    TextView tv_inventory_asset_class;
    @BindView(R.id.sp_inventory_brand_name)
    Spinner sp_inventory_brand_name;
    @BindView(R.id.tv_inventory_use_department)
    TextView tv_inventory_use_department;
    @BindView(R.id.sp_inventory_location)
    Spinner sp_inventory_location;
    @BindView(R.id.tv_inventory_model_name)
    TextView tv_inventory_model_name;
    @BindView(R.id.sp_inventory_datacenter_name)
    Spinner sp_inventory_datacenter_name;
    @BindView(R.id.tv_inventory_manage_branch)
    TextView tv_inventory_manage_branch;
    private InventoryDetail inventoryDetail;
    private Dialog mDialog;
    public InventoryDetailView(Fragment fragment, View view) {
        this.fragment = fragment;
        mDialog = CustomProgressDialog.createLoadingDialog(fragment.getContext(), "正在加载中...");
        ButterKnife.bind(this,view);
    }

    /**
     * 设置资产信息
     * @param inventoryDetail
     * @param locationIndex
     * @param brandIndex
     * @param typeIndex
     * @param userDepartIndex
     * @param userDepartIndex
     * @param dataIndex
     */
    public void showAssetDetail(InventoryDetail inventoryDetail, long locationIndex, long brandIndex,
                                long typeIndex,long userDepartIndex,long dataIndex,long opDepartIndex){
        tv_inventory_asset_name.setText(inventoryDetail.getAssetName());
        tv_inventory_sn_no.setText(inventoryDetail.getAssetNo());
        tv_inventory_rfid_no.setText(inventoryDetail.getRfidNo());
        tv_inventory_asset_class.setText(inventoryDetail.getTypeName());
        tv_inventory_model_name.setText(inventoryDetail.getModelName());
        sp_inventory_brand_name.setSelection(Integer.valueOf(brandIndex+""));
        tv_inventory_use_department.setText(inventoryDetail.getUseBranchId_());
        sp_inventory_location.setSelection(Integer.valueOf(locationIndex+""));
        sp_inventory_datacenter_name.setSelection(Integer.valueOf(dataIndex+""));
        tv_inventory_manage_branch.setText(inventoryDetail.getManageBranchId_());
    }

    public InventoryDetail saveAssetDetail(InventoryDetail preInventoryDetail){
        inventoryDetail.setAssetName(tv_inventory_asset_name.getText().toString());
        inventoryDetail.setAssetNo(tv_inventory_sn_no.getText().toString());
        inventoryDetail.setRfidNo(tv_inventory_rfid_no.getText().toString());
        inventoryDetail.setTypeName(tv_inventory_asset_class.getText().toString());
        inventoryDetail.setModelName(tv_inventory_model_name.getText().toString());
        if(preInventoryDetail!=null) {
            inventoryDetail.setBrandName(preInventoryDetail.getRoomName());
            inventoryDetail.setEndUser(preInventoryDetail.getBrandName());
            inventoryDetail.setRoomName(preInventoryDetail.getTypeName());
            inventoryDetail.setDatacenterId_(preInventoryDetail.getTypeName());
            inventoryDetail.setManageBranchId_(preInventoryDetail.getTypeName());
        }
        return inventoryDetail;
    }

    public void showProgressDialog(String msg){
        mDialog.show();
    }

    public void hideProgressDialog(){
        mDialog.hide();
    }

    public void showToast(String msg){
        ToastUtil.toastShort(msg);
    }

}
